<template>
	<view>

		<!-- 首页 -->
		<index ref="index" v-if="loadedTabs[0]" v-show="value == 0"></index>
		<!-- end -->

		<!-- 商会成员 -->
		<level ref="level" v-if="loadedTabs[1]" v-show="value == 1"></level>
		<!-- end -->

		<!-- 商会我的页面 -->
		<my v-if="loadedTabs[2]" v-show="value == 2"></my>
		<!-- end -->

		<!-- 自定义导航栏 -->
		<u-tabbar :zIndex='999' :value="value" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true">
			<u-tabbar-item text="首页" icon="home" @click="click"></u-tabbar-item>
			<u-tabbar-item text="成员" icon="level" @click="click"></u-tabbar-item>
			<u-tabbar-item text="我的" icon="account" @click="click"></u-tabbar-item>
		</u-tabbar>
		<!-- end -->
	</view>
</template>

<script>
	import {
		configMap
	} from "@/utils";
	import {
		mapGetters
	} from "vuex";
	import {
		comDetail,
	} from '@/api/extend.js';
	import my from '@/pages/extend/chamber/components/my.vue';
	import index from '@/pages/extend/chamber/components/index.vue';
	import level from '@/pages/extend/chamber/components/level.vue';
	export default {
		components: {
			index,
			level,
			my
		},
		data() {
			return {
				chamberObj: {},
				chamber_id: '',
				value: 0,
				loadedTabs: [true, false, false] // 记录每个tab是否已加载过
			}
		},
		computed: {
			...configMap({}, mapGetters(['isLogin', 'uid', 'userInfo'])),

		},
		onLoad(options) {
			this.chamber_id = options.cid;
			if (options.scene) {
				let value = this.$util.getUrlParams(decodeURIComponent(options.scene));
				if (value.cid) {
					this.chamber_id = value.cid;
				}
			}
			this.getcomDetailFunc();

		},

		// #ifdef MP
		onShareAppMessage: function() {
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			})
			return {
				title: this.chamberObj.nickname || '',
				path: `pages/extend/chamber/chamber_home?uid=${this.uid || -1}&cid=${this.chamber_id}`,
			}
		},
		onShareTimeline: function() {
			return {
				title: this.chamberObj.nickname || '',
				query: {
					uid: this.uid,
					cid: this.chamber_id
				},
				imageUrl: ''
			}
		},
		// #endif
		onPageScroll() {
			uni.$emit('scroll');
		},
		onReachBottom() {
			if (this.value == 0) {
				uni.$emit('onReachBottom')
			}
			if (this.value == 1) {
				uni.$emit('onReachBottom')
			}
		},
		methods: {
			getcomDetailFunc() {
				comDetail({
					com_id: this.chamber_id
				}).then(res => {
					this.$store.commit('SET_ChamberObj', res.data);
					this.chamberObj = res.data;
					this.$refs.index.referData();

					uni.setStorageSync('store_import', {
						type: 'chamber',
						chamber_id: res.data.id
					});
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'none'
					})
				})
			},
			click(e) {
				// 标记该tab已加载
				this.loadedTabs[e] = true;
				this.value = e;
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>